package device

import (
	"encoding/json"
	"gitee.com/zhanghuamingmyself/util"
)

type IotDeviceSensorData struct {
	Val         map[string]string `json:"val"`
	CreatedTime int32             `json:"createdTime"`
}

type IotDeviceSensorDataWithExplain struct {
	ExplainList []IotDeviceExplain    `json:"explainList"`
	DataList    []IotDeviceSensorData `json:"dataList"`
}

type IotDeviceSensorDataListReq struct {
	DeviceCore   string `json:"deviceCore"`
	Port         string `json:"port"`
	StartTime    int64  `json:"startTime"`
	EndTime      int64  `json:"endTime"`
	EnableEval   *bool   `json:"enableEval"`
	FilterRepeat *bool   `json:"filterRepeat"`
}

func ListDeviceSensorData(req IotDeviceSensorDataListReq) ([]IotDeviceSensorData, error) {
	var deviceSensorDataList []IotDeviceSensorData
	bytes, err := util.PostJson(deviceSensorBasePath+"data/list", req)
	if err != nil {
		return deviceSensorDataList, err
	}
	json.Unmarshal(bytes, &deviceSensorDataList)
	return deviceSensorDataList, nil
}

func ListDeviceSensorDataWithExplain(req IotDeviceSensorDataListReq) (IotDeviceSensorDataWithExplain, error) {
	var deviceSensorDataWithExplain IotDeviceSensorDataWithExplain
	bytes, err := util.PostJson(deviceSensorBasePath+"data/listWithExplain", req)
	if err != nil {
		return deviceSensorDataWithExplain, err
	}
	json.Unmarshal(bytes, &deviceSensorDataWithExplain)
	return deviceSensorDataWithExplain, nil
}
